/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include "machine/pc/processor/x86/interruptstate.h"

const char *InterruptStateRegisterName[16] = {
	"eax", "ebx", "ecx", "edx", "edi", "esi", "ebp", "esp", "eip", "eflags", "res", "esp", "ds", "ss", "cs"
};

uintptr_t InterruptState::getSyscallParameter(size_t n) const {
	switch (n) {
		case 0:
			return m_Ebx;
		case 1:
			return m_Ecx;
		case 2:
			return m_Edx;
		case 3:
			return m_Esi;
		case 4:
			return m_Edi;
		default:
			return 0;
	}
	return 0;
}

processor_register_t InterruptState::getRegister(size_t index) const {
	switch(index) {
		case 0:
			return m_Eax;
		case 1:
			return m_Ebx;
		case 2:
			return m_Ecx;
		case 3:
			return m_Edx;
		case 4:
			return m_Edi;
		case 5:
			return m_Esi;
		case 6:
			return m_Ebp;
		case 7:
			return getStackPointer();
		case 8:
			return m_Eip;
		case 9:
			return m_Eflags;
		case 10:
			return m_Res;
		case 11:
			return m_Esp;
		case 12:
			return m_Ds;
		case 13:
			return m_Ss;
		case 14:
			return m_Cs;
		default:
			return 0;
	}
	return 0;
}

const char *InterruptState::getRegisterName(size_t index) const {
	return InterruptStateRegisterName[index];
}
